// pages/logs/logs.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showVideo: [],
    showVideoView: [],
    video:'',
    audio:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData()
  },
  //点击播放录音  
  gotoPlay: function (e) {
    var filePath = this.data.audio[e.currentTarget.dataset.index].video
    console.log('filePath=' + filePath)
    //点击开始播放  
    wx.showToast({
      title: '开始播放',
      icon: 'success',
      duration: 1000
    })
    // wx.downloadFile({
    //   url: filePath, //仅为示例，并非真实的资源
    //   success: function (res) {
    //     console.log('success')
    //     console.log(res)
    //     wx.playVoice({
    //       filePath: res.tempFilePath
    //     })
    //   }, fail(e) {
    //     console.log('fail')
    //     console.log(e)
    //   }
    // })


    wx.playBackgroundAudio({
      dataUrl: filePath,
      title: '',
      coverImgUrl: ''
    })

    // wx.playVoice({
    //   filePath: 'http://xiaochengxu-ajihua.oss-cn-hangzhou.aliyuncs.com/voice/__jMRKXJmkPFsFko1502265220443.silk',
    //   success: function () {
    //     console.log('success')
    //   },fail(){
    //     console.log('fail')
    //   }
    // })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  getData: function () {
    var that = this
    wx.request({
      url: 'https://xiaochengxu.fincoder.com/index.php/Home/Index/index_nologi_all',
      data: {

      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        if (res.data.status === 1) {
          that.setData({
            video: res.data.video,
            audio: res.data.audio,
          })
          console.log('ddsss=' + that.data.description)
          var tem1 = []
          var temp2 = []
          if (that.data.video!=null){
            for (var i = 0; i < that.data.video.length; i++) {
              tem1.push(false)
              temp2.push(true)
            }
            that.setData({
              showVideo: tem1,
              showVideoView: temp2,
            })
          }
        
      
        } else {

        }
      }, fail: function () {
      },
      complete: function () {

      }
    })
  },
  bindPlay: function (e) {

  

    var index = e.currentTarget.dataset.index
    console.log(index)
    this.videoContext = wx.createVideoContext('video' + index)

    this.videoContext.play({

    })
    var tem1 = this.data.showVideo
    var tem2 = this.data.showVideoView
    tem1[index] = true
    tem2[index] = false
    this.setData({
      showVideo: tem1,
      showVideoView: tem2,
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    console.log('onHide')
    wx.stopBackgroundAudio()
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    console.log('onUnload')
    wx.stopBackgroundAudio()
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})